home *** CD-ROM | disk | FTP | other *** search
/ Whiteline: Alpha / Whiteline Alpha.iso / progtool / prolog / prologsh / proshell.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-22  |  11.7 KB  |  357 lines

  1. /********************************************************************/
  2. /*                                                                   */
  3. /*                       TOY-PROLOGshell                            */
  4. /*                     <c> Dr. Sarnow                                */
  5. /*                 für die PD der ST-Computer                        */
  6. /*               zum persönlichen Gebrauch freigegeben                */
  7. /*                                                                    */
  8. /********************************************************************/
  9.  
  10. #include <obdefs.h>    
  11. #include <gemdefs.h>
  12. #include <osbind.h>
  13. #include <stdio.h>
  14. #include <string.h>
  15. #include "proshell.h"
  16.  
  17. #define TRUE (1)
  18. #define FALSE (0)
  19. #define DEBUG            
  20.  
  21. /*************************** idiotisches GEM Geblasel **************/            
  22. int contrl[12],
  23.     intin[128],
  24.     intout[128],
  25.     ptsin[128],
  26.     ptsout[128] ;
  27.  
  28. int work_in[12],
  29.     work_out[57] ;
  30. int pxyarray[10] ;
  31.  
  32. int handle ;
  33. OBJECT *menu_tree,*formular,*urheber,*optfiles;
  34.  
  35. FILE *optfilebuffer;
  36.  
  37. int mouse ;             /* mouse ein = 1, aus = 0             */
  38. int gl_dummy ;       /* globaler dummy */
  39. int dix,diy,diw,dih ; /* dialog box parameter */
  40. int x_info,y_info,w_info,h_info;
  41. int x_opt,y_opt,w_opt,h_opt;
  42. int obval;
  43. int xwork,ywork,wwork,hwork;
  44. int xfull,yfull,wfull,hfull;
  45.  
  46. int msgbuff[32] ;
  47.  
  48. char options[7][20],d[20],lspfile[20],was[30],akt[13],pf[150],*xlopt;
  49.  
  50.  
  51. /* globale Variablen für den Gebrauch  der Window Routinen aus der */
  52. /* MEGAMAX Tool Diskette Nr. 4*/
  53.  
  54. static int whandle[5] ; /* window-handle fuer max. 4 fenster */
  55. static int ax[5],ay[5],aw[5],ah[5] ;  /* koord. der arbeitsbereiche */
  56. static int bx[5],by[5],bw[5],bh[5] ;  /* koord. der bildbereiche */
  57. static int posx[5],posy[5] ; /* koord. des linken oberen eckpkts */
  58.                       /*  im virtuellen fenster */
  59. static int fulled[5] ; /* fenster fulled oder nicht */
  60. static int wikind[5] ; /* fensterattribute */
  61. static int wopen[5] ; /* fenster offen oder zu */
  62. static char *speich[5] ; /* anfangsadressen der speicherbereiche */
  63. static char *base[5] ; /* anfangsadressen der screens */
  64. static int maxwd ;     /* nummer des hoechsten windows muss zu anfang auf 0
  65.                    gesetzt werden */
  66. static char *bild ;
  67. static int mwidth,mheight,mplane ;
  68. static int wd_handle ;
  69.  
  70. /************** Öffnet virtuelle Arbeitstation ************/
  71.  
  72. open_vwork()
  73. {
  74.  int i,dummy;
  75.   appl_init();
  76.   handle=graf_handle(&gl_dummy,&gl_dummy,&gl_dummy,&gl_dummy);
  77.   for (i=0;i<10;work_in[i++]=1);
  78.   work_in[10]=2;
  79.   v_opnvwk(work_in,&handle,work_out);
  80.   graf_mouse(0,&gl_dummy) ;
  81. }
  82.  
  83. /******************* Schließt dieselbe  *********************/
  84.  
  85. close_vwork()
  86. {
  87.  v_clsvwk(handle);
  88.  appl_exit();
  89.  Pterm0();
  90. }
  91.  
  92. /********************** Maus an *****************************/
  93.  
  94. show_mouse()
  95. { if (!mouse)
  96.   { graf_mouse(257,&gl_dummy) ;
  97.     mouse = TRUE ;
  98.   }
  99. }
  100.  
  101. /*************** Und wieder aus ********************************/
  102.  
  103. hide_mouse()
  104. { if (mouse)
  105.   { graf_mouse(256,&gl_dummy) ;
  106.     mouse = FALSE ;
  107.   }
  108. }
  109.  
  110. /*************************************************************/
  111. /*    hauptprogramm                                          */
  112. /*************************************************************/
  113.  
  114. main()
  115. {
  116.   int reso ;
  117.   open_vwork() ;
  118.   if (!rsrc_load("proshell.rsc"))
  119.   {
  120.     form_alert(1,"[3][Ich kann PROSHELL.RSC nicht finden !][Abbruch]");
  121.     close_vwork();
  122.   }
  123.   if (!rsrc_gaddr(0,LEISTE,&menu_tree))
  124.   {
  125.     form_alert(1,"[3][Resource File nicht ok !][Abbruch]");
  126.     close_vwork();
  127.   }
  128.  
  129.   if (!Getrez()==2)
  130.   {
  131.      form_alert(1,"[3]['tschuldigung,|funktioniert nur|mit hoher|Auflösung.][ Meinetwegen ]");
  132.      close_vwork();
  133.   }
  134.  
  135.   /* variablen setzen */
  136.  
  137.   mouse = TRUE ; /*Maus an*/
  138.   xlopt=malloc(310); /*Speicherplatz für Hilfsstring bereitstellen*/
  139.   strcpy(pf,"A:\\*.*"); /*Setze Pfad String auf das*/
  140.   *pf=Dgetdrv()+65;     /*aktuelle Laufwerk*/
  141.   menu_bar(menu_tree,TRUE) ;  /*Menüleiste anzeigen*/
  142.   rsrc_gaddr(R_TREE,KNOEPFE,&formular); /* Adresse des Formulars holen*/
  143.   strcpy(lspfile,"TEST"); /*Setze Default Prolog File*/
  144.   (((TEDINFO *)(formular[PROFILE].ob_spec))->te_ptext)=lspfile; /*Objektkomponenete->te_ptext zeigt auf 
  145.                                                                   /* den String lispfile*/
  146.   form_center(formular,&dix,&diy,&diw,&dih);/*Zentriere das Formular*/
  147.   rsrc_gaddr(R_TREE,AUTOR,&urheber);/*Hol die Adresse der Infoschablone*/
  148.   form_center(urheber,&x_info,&y_info,&w_info,&h_info);   /*und zentriere sie*/
  149.   rsrc_gaddr(R_TREE,OPTFILES,&optfiles);/*Hol die Adresse der Hilfsfileschablone*/
  150.   (((TEDINFO *)(optfiles[NAME1].ob_spec))->te_ptext)=options[0];/*und verbiege alle Stringpointer*/
  151.   (((TEDINFO *)(optfiles[NAME2].ob_spec))->te_ptext)=options[1];/*sodaß sie auf die Strings für die*/
  152.   (((TEDINFO *)(optfiles[NAME3].ob_spec))->te_ptext)=options[2];/*Files zeigen*/
  153.   (((TEDINFO *)(optfiles[NAME4].ob_spec))->te_ptext)=options[3];
  154.   (((TEDINFO *)(optfiles[NAME5].ob_spec))->te_ptext)=options[4];
  155.   (((TEDINFO *)(optfiles[NAME6].ob_spec))->te_ptext)=options[5];
  156.   (((TEDINFO *)(optfiles[NAME7].ob_spec))->te_ptext)=options[6];
  157.   form_center(optfiles,&x_opt,&y_opt,&w_opt,&h_opt);/*Zentriere das Formular*/
  158.   wind_get(0,WF_WORKXYWH,&xfull,&yfull,&wfull,&hfull);/*Hol die Fensterkoordinaten*/
  159.   wikind[1]=NAME | INFO;/*FEnsterelemente festlegen*/
  160.   wind_calc(WC_WORK,wikind[1],xfull,yfull,wfull,hfull,&xwork,&ywork,&wwork,&hwork);/*Berechne Koordinaten*/
  161.                                                               /*für den Arbeitsbereich*/
  162.   maxwd=0;/* Ist angeblich für die FEnsterroutinen erforderlich*/
  163.   wd_init(handle);/*Initialisiere die Fensterroutinen der MM-Window_routinen*/
  164.   whandle[1]=wd_open(wikind[1],xwork,ywork,wwork,hwork);/*Öffne das Fenster*/
  165.   wd_title(whandle[1],"TOY-PROLOGshell");/*Text für Titelzeile ausgeben*/
  166.   wd_info(whandle[1],"                                  \275 Dr. Sarnow");
  167.                                       /*Text für Infozeile ausgeben*/
  168.   wd_clr(whandle[1]);/*Lösche Fensterinhalt*/
  169.   wd_update(whandle[1]);/*Aktualisiere Fensterinhalt*/
  170.   multi() ;/*Verwaltet alle Ereignisse*/
  171.  
  172. }
  173.  
  174. multi()
  175. { int event,mx,my,dummy,keycode;
  176.   char *hilfe;
  177.  
  178.   do
  179.   { 
  180.        objc_draw(formular,0,MAX_DEPTH,dix,diy,diw,dih);/*Zeichne das Formular neu*/
  181.      event = evnt_multi(MU_KEYBD | MU_BUTTON | MU_MESAG,       /*Warten auf...*/
  182.                        1,1,1,
  183.                        FALSE,0,0,0,0,
  184.                        FALSE,0,0,0,0,
  185.                        msgbuff,0,0,
  186.                        &mx,&my,&dummy,&dummy,&keycode,&dummy) ;
  187.  
  188.     wd_redraw(msgbuff);/*Automatischer Redraw Befehl (MMTOOL4)*/
  189.  
  190.     if (event & MU_MESAG)    /*Menüleiste gewählt*/
  191.     { switch(msgbuff[0])
  192.       { case MN_SELECTED : do_menu(msgbuff[3],msgbuff[4]) ;
  193.                            break ;
  194.         
  195.       }
  196.     }
  197.  
  198.     /* weitere abfragen */
  199.    if (event & MU_BUTTON)
  200.    {
  201.       obval=objc_find(formular,0,MAX_DEPTH,mx,my);/*Finde angeklicktes Objekt*/
  202.       menu_bar(menu_tree,FALSE);/*Menüleiste aus*/
  203.       switch(obval)
  204.       {
  205.          case PROLOG:/* Es war der TOY-PROLOG-Knopf*/
  206.              wd_close(whandle[1]);/*Fenster dicht*/
  207.              hide_mouse();
  208.              optfilebuffer=fopen("optionen","w");/*Leider akzeptiert */
  209.              strcpy(xlopt,"['");                    /*TOY-Prolog keine*/
  210.              xlopt=strcat(xlopt,lspfile);        /*Parameter. Deshalb*/
  211.              xlopt=strcat(xlopt,"'");            /*der Umweg über */
  212.              for (dummy=0;dummy<7;dummy++)        /*eine externe Datei.*/
  213.              {
  214.                  if (strlen(options[dummy])>1)
  215.                  {
  216.                      xlopt=strcat(xlopt,",'");
  217.                      xlopt=strcat(xlopt,options[dummy]);
  218.                      xlopt=strcat(xlopt,"'");
  219.                  } 
  220.              }
  221.              xlopt=strcat(xlopt,"]");
  222.              fprintf(optfilebuffer,"%s\n",xlopt);
  223.              fclose(optfilebuffer);
  224.             Pexec(0,"toy.prg","",0L);    /*Los geht's*/
  225.             show_mouse();
  226.             graf_mouse(0,0L);
  227.             wd_display(whandle[1],xfull,yfull,wfull,hfull);/*Fenster auf*/
  228.             break;
  229.             
  230.          case EDITOR:        /*Wie bei TOY-PROLOG*/
  231.              wd_close(whandle[1]);
  232.             strcpy(xlopt," ");
  233.             xlopt=strcat(xlopt,lspfile);
  234.             hide_mouse();
  235.             Pexec(0,"editor.prg",xlopt,0L);
  236.             show_mouse();
  237.             wd_display(whandle[1],xfull,yfull,wfull,hfull);
  238.             break;
  239.             
  240.          case OPTIONEN:    /*Wähle Optionsfile*/
  241.             keycode=opt();/*Welcher Button wird gedrückt?*/
  242.             strcpy(d,options[keycode]);                /*Auswahl erfolgt mit*/
  243.             strcpy(was," Prolog Hilfsfile wählen ");    /*Hilfe der File Selector-Routine*/
  244.             strcpy(akt," OK ");                        /*aus der MM-tool Diskette 4*/
  245.             file_select(pf,d,was,akt,"*.PRO","*.*","*.*","*.*",2);/*Aufruf derselben*/
  246.             if ((hilfe=index(d,'.'))!=NULL && strcmp(++hilfe,"TOY")==0)
  247.             {
  248.                 form_alert(1,"[3][*.TOY Files müssen mit|sysload(Name)|geladenwerden][Grummel]");
  249.             }
  250.             else
  251.             {
  252.                 strcpy(options[keycode],d);/*gewählte Datei festhalten*/            
  253.             }
  254.             break;
  255.             
  256.             
  257.          case PROFILE:        /*Prolog Workfile wählen*/
  258.             strcpy(d,lspfile);/*sonst wie bei Options*/
  259.             strcpy(was," Prolog File wählen ");
  260.             strcpy(akt," OK ");
  261.             file_select(pf,d,was,akt,"*.PRO","*.*","*.*","*.*",2);
  262.             if ((hilfe=index(d,'.'))!=NULL && strcmp(++hilfe,"TOY")==0)
  263.             {
  264.                 form_alert(1,"[3][*.TOY Files müssen mit|sysload(Name)|geladenwerden][Grummel]");
  265.             }
  266.             else
  267.             {
  268.                 strcpy(lspfile,d);
  269.             }
  270.             break;
  271.             
  272.          case CIAO:    /*Tschüs, au revoir, good bye*/
  273.              wd_delete(whandle[1]);
  274.              rsrc_free();
  275.             show_mouse();
  276.             close_vwork();
  277.             break;
  278.       }
  279.       menu_bar(menu_tree,TRUE);
  280.    }
  281.   
  282.   }while(TRUE) ;
  283.  
  284. } /* multi */
  285.  
  286. do_menu(title,item)/*Routine führt die in der Menüleiste gewählte*/
  287. int title,item ;     /*Routine aus. Hat hier nicht viel zu tun*/
  288. { switch(title)
  289.   { case DESK  : 
  290.          switch(item)
  291.          { case INFORM : info() ; break ;
  292.          }
  293.    
  294.   }
  295.   menu_tnormal(menu_tree,title,1) ;/*Menütitel wieder normal zeichnen*/
  296.  
  297. } /* do menu */
  298.  
  299. info()     /*Zeige das Info-formular*/
  300. {       
  301.    form_dial(FMD_START,320,200,0,0,x_info,y_info,w_info,h_info);
  302.    form_dial(FMD_GROW,320,200,0,0,x_info,y_info,w_info,h_info);
  303.    objc_draw(urheber,0,20,x_info,y_info,w_info,h_info);
  304.    objc_change(urheber,INFOEX,0,x_info,y_info,w_info,h_info,(NORMAL | OUTLINED | SHADOWED),1);
  305.    form_do(urheber,0);
  306.    form_dial(FMD_SHRINK,320,200,0,0,x_info,y_info,w_info,h_info);
  307.    form_dial(FMD_FINISH,320,200,0,0,x_info,y_info,w_info,h_info);
  308. }
  309.  
  310. opt()    
  311. {       
  312.    int wahl;
  313.    char *str;
  314.    
  315.    form_dial(FMD_START,320,200,0,0,x_opt,y_opt,w_opt,h_opt);/*Zeige das Formular*/
  316.    form_dial(FMD_GROW,320,200,0,0,x_opt,y_opt,w_opt,h_opt); /*für die Wahl der Hilfs-*/
  317.    objc_draw(optfiles,0,20,x_opt,y_opt,w_opt,h_opt);        /*routinen*/
  318.    form_do(optfiles,0);
  319.    form_dial(FMD_SHRINK,320,200,0,0,x_opt,y_opt,w_opt,h_opt);
  320.    form_dial(FMD_FINISH,320,200,0,0,x_opt,y_opt,w_opt,h_opt);
  321.    wahl=dialog_wahl(optfiles,BUTTON1,BUTTON7);/*finde den gedrückten Knopf (aus MMtool 4)*/
  322.    objc_change(optfiles,wahl,0,x_opt,y_opt,w_opt,h_opt,NORMAL,0);/*Stelle ihn wieder normal dar*/
  323.    switch (wahl)    /*Leider haben nicht alle Objekte den gleiche Offset*/
  324.    {
  325.       case BUTTON1:
  326.          wahl=0;
  327.          break;
  328.  
  329.       case BUTTON2:
  330.          wahl=1;
  331.          break;
  332.          
  333.       case BUTTON3:
  334.          wahl=2;
  335.          break;
  336.  
  337.       case BUTTON4:
  338.          wahl=3;
  339.          break;
  340.  
  341.       case BUTTON5:
  342.          wahl=4;
  343.          break;
  344.  
  345.       case BUTTON6:
  346.          wahl=5;
  347.          break;
  348.  
  349.       case BUTTON7:
  350.          wahl=6;
  351.          break;
  352.  
  353.    }
  354.    return(wahl);
  355. }
  356.  
  357.